<!--
 * @Author: hujunjie hujunjie@shudatech.cn
 * @Date: 2025-01-03 09:53:32
 * @LastEditors: hujunjie hujunjie@shudatech.cn
 * @LastEditTime: 2025-01-07 14:13:47
 * @FilePath: \Shuda_Pure_PC\src\views\production\equipment\index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
      @submit.native.prevent
    >
      <el-form-item label="设备名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="输入设备名称"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备编号" prop="code">
        <el-input
          v-model="queryParams.code"
          placeholder="输入设备编号"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备类型" prop="type">
        <el-select
          v-model="queryParams.type"
          placeholder="选择设备类型"
          @change="handleQuery"
        >
          <el-option
            v-for="dict in dict.type.biz_device_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="设备状态" prop="deviceStatus">
        <el-select
          v-model="queryParams.deviceStatus"
          placeholder="选择设备状态"
          @change="handleQuery"
        >
          <el-option
            v-for="dict in dict.type.biz_device_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['production:equipment:add']"
          >新增设备</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
        :columns="columns"
      ></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="tableList">
      <el-table-column label="序号" type="index" align="center">
        <template slot-scope="scope">
          <span>{{
            (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="设备名称"
        align="center"
        key="name"
        prop="name"
        v-if="findColumnsVisible('name')"
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <div class="text-detail" @click="handleToDetail(scope.row)">
            {{ scope.row.name || "-" }}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="设备类型"
        align="center"
        key="type"
        prop="type"
        v-if="findColumnsVisible('type')"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.biz_device_type"
            :value="scope.row.type"
          ></dict-tag>
        </template>
      </el-table-column>
      <el-table-column
        label="设备编号"
        align="center"
        key="code"
        prop="code"
        v-if="findColumnsVisible('code')"
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <div>{{ scope.row.code || "-" }}</div>
        </template>
      </el-table-column>
      <el-table-column
        label="所属基地"
        align="center"
        key="productionBaseName"
        prop="productionBaseName"
        v-if="findColumnsVisible('productionBaseName')"
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <div>{{ scope.row.productionBaseName || "-" }}</div>
        </template>
      </el-table-column>
      <el-table-column
        label="所属塘口"
        align="center"
        key="culturePondName"
        prop="culturePondName"
        v-if="findColumnsVisible('culturePondName')"
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <div>{{ scope.row.culturePondName || "-" }}</div>
        </template>
      </el-table-column>
      <el-table-column
        label="设备状态"
        align="center"
        key="deviceStatus"
        prop="deviceStatus"
        v-if="findColumnsVisible('deviceStatus')"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.biz_device_status"
            :value="scope.row.deviceStatus"
          ></dict-tag>
        </template>
      </el-table-column>
      <!-- <el-table-column
        label="出厂日期"
        align="center"
        key="productionDate"
        prop="productionDate"
        v-if="findColumnsVisible('productionDate')"
      >
        <template slot-scope="scope">
          <div>{{ scope.row.productionDate || "-" }}</div>
        </template>
      </el-table-column> -->

      <el-table-column
        label="投运日期"
        align="center"
        key="useDate"
        prop="useDate"
        v-if="findColumnsVisible('useDate')"
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <div>{{ scope.row.useDate || "-" }}</div>
        </template>
      </el-table-column>

      <el-table-column
        label="操作"
        align="center"
        width="200"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope" v-if="scope.row.userId !== 1">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['production:equipment:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            class="btn-danger"
            @click="handleDelete(scope.row)"
            v-hasPermi="['production:equipment:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <Edit
      :visible.sync="editOpen"
      :params="editParams"
      @success="getList"
    ></Edit>
    <Detail :visible.sync="detailOpen" :params="detailParams"></Detail>
  </div>
</template>
  
<script>
import Edit from "./edit.vue";
import Detail from "./detail.vue";
import mixins from "@/mixins";
import { list,remove } from "@/api/production/equipment";

export default {
  name: "production-equipment_index",
  dicts: ["biz_device_type","biz_device_status"],
  mixins: [mixins],
  components: { Edit, Detail },
  data() {
    return {
      placeholderImg: require("@/assets/images/production.png"),
      baseUrl: process.env.VUE_APP_BASE_API,
      // 编辑模态框参数
      editParams: {
        type: "add",
        title: "",
      },
      // 是否显示弹出层
      editOpen: false,
      detailOpen: false,
      detailParams: {
        id: "",
      },
      // 遮罩层
      loading: false,
      tableList: [],
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: undefined,
        type: undefined,
        deviceStatus:undefined,
        code:undefined
      },
      // 列信息
      columns: [
        { key: "name", label: `设备名称`, visible: true },
        { key: "type", label: `设备类型`, visible: true },
        { key: "code", label: `设备编号`, visible: true },
        { key: "productionBaseName", label: `所属基地`, visible: true },
        { key: "culturePondName", label: `所属塘口`, visible: true },
        { key: "deviceStatus", label: `设备状态`, visible: true },
        { key: "productionDate", label: `出厂日期`, visible: true },
        { key: "useDate", label: `投运日期`, visible: true },
      ],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查看详情 */
    handleToDetail(row) {
      this.detailParams = { title: "设备信息", id: row.id };
      this.detailOpen = true;
    },
    /** 数据列表 */
    getList() {
      this.loading = true;
      list(this.queryParams).then((response) => {
        this.tableList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.editParams = { title: "添加设备", type: "add" };
      this.editOpen = true;
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.editParams = { title: "修改信息", type: "edit", id: row.id };
      this.editOpen = true;
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      this.$modal
        .confirm('是否确认删除"' + row.name + '"设备的数据项？')
        .then(function () {
          return remove({ id: row.id });
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
  },
};
</script>
<style scoped lang="scss">
.production-first {
  display: flex;
  align-items: center;
  & > img {
    width: 50px;
    height: 50px;
    flex-shrink: 0;
    margin-right: 10px;
  }
  .info {
    .title {
      font-size: 22px;
      font-weight: bold;
      cursor: pointer;
    }
    .address {
      color: #909399;
    }
  }
}
</style>